package com.graduate.cec.controller;


import com.graduate.cec.common.JsonPage;
import com.graduate.cec.common.JsonResult;
import com.graduate.cec.pojo.dto.NationDTO;
import com.graduate.cec.pojo.dto.NationSimpleDTO;
import com.graduate.cec.pojo.entity.Nation;
import com.graduate.cec.pojo.vo.NationVO;
import com.graduate.cec.service.NationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/nation",produces = "application/json;charset=utf-8")
@Api(tags = "民族")
public class NationController {

    @Resource
    private NationService nationService;

    /****************        增       ******************************************************************/
    @GetMapping("/insert-nation")
    @ApiOperation("增加")
    public JsonResult<NationVO> insertNation(NationDTO nationDTO){
        nationService.insertNation(nationDTO);
        return JsonResult.ok("插入成功");
    }



    /****************        删       ******************************************************************/
    @GetMapping("/delete-by-keys/{id}")
    @ApiOperation("通过主键删除")
    public JsonResult<Void> deleteByKeys(@PathVariable Long id){
        log.info("ids:{}", id);
        nationService.deleteByKeys(id);
        return JsonResult.ok("删除成功");
    }


    /****************        改       ******************************************************************/
    @PostMapping("/update-by-key")
    @ApiOperation("通过主键修改内容")
    public JsonResult<Void> updateByKey(@RequestBody NationDTO nationDTO){
        log.info("nationDTO:{}",nationDTO);
        nationService.updateByKey(nationDTO);
        return JsonResult.ok("修改成功");
    }


    /****************        查        ******************************************************************/
    /**
     * 根据查询条件查找列表
     * @param nationSimpleDTO 条件
     * @return JsonResult<JsonPage<NationVO>>
     */
    @GetMapping("/get-list-by-example")
    @ApiOperation("通过一定条件(姓名)查找列表")
    public JsonResult<JsonPage<Nation>> getListByExample(NationSimpleDTO nationSimpleDTO){
        log.info("nationDTO:{}", nationSimpleDTO);

        JsonPage<Nation> jsonPage = nationService.getListByExample(nationSimpleDTO);
        return JsonResult.ok("查询成功",jsonPage);
    }

    /**
     * 查询所有列表
     * @return JsonResult<List<NationVO>>
     */
    @GetMapping("/get-all-list")
    @ApiOperation("查询全部列表")
    public JsonResult<List<Nation>> getAllList(){
        return JsonResult.ok("查询成功",nationService.getAllList());
    }

    @GetMapping("/get-nation-by-id")
    @ApiOperation("查询民族详情")
    public JsonResult<NationVO> getNationById(Long id){
        return JsonResult.ok("查询成功",nationService.getNationById(id));
    }






}
